package com.ql.service.zydj;

import com.ql.dao.zyyz.ZyyzMapper;
import com.ql.pojo.zyyz.Zuyuanyz;
import com.ql.utils.PageHelper;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service("zuyuanyzService")
public class ZuyuanyzServiceImpl implements ZuyuanyzService {
    private static final Logger LOGGER = Logger.getLogger( ZuyuanyzServiceImpl.class );
    @Resource
    private ZyyzMapper zyyzMapper;

    //根据住院号查找医嘱列表
    public List<Zuyuanyz> qryAllYz(int userId, PageHelper ph) {
        List<Zuyuanyz> zuyuanyzs = null;
        try {
            ph.setTotalCount( zyyzMapper.qryCount( userId ) );
            zuyuanyzs = zyyzMapper.qryByUserId( userId, (ph.getCurrentPageNo() - 1) * ph.getPageSize(), ph.getPageSize() );
        } catch (Exception e) {
            LOGGER.error( "ZuyuanyzServiceImpl.qryAllYz异常" + e.getMessage() );
        }
        return zuyuanyzs;
    }

    //查找未执行医嘱列表
    @Override
    public List<Zuyuanyz> qryAllUn(int userId,String qryUserName,String qryKeshi,PageHelper ph) {
        List<Zuyuanyz> zuyuanyzs = null;
        try {
            ph.setTotalCount( zyyzMapper.qryYZ(userId,qryUserName,qryKeshi) );
            zuyuanyzs = zyyzMapper.qryUnYZ( userId,qryUserName,qryKeshi,(ph.getCurrentPageNo() - 1) * ph.getPageSize(), ph.getPageSize() );
        } catch (Exception e) {
            LOGGER.error( "ZuyuanyzServiceImpl.qryAllUn异常" + e.getMessage() );
        }
        return zuyuanyzs;
    }

    @Override
    public boolean addYz(Zuyuanyz zuyuanyz) {
        int row = 0;
        try {
            row = zyyzMapper.addYz( zuyuanyz );
            if (row == 1) {
                System.out.println( "添加成功" );
                return true;
            } else {
                System.out.println( "添加失败" );
                return false;
            }
        } catch (Exception e) {
            LOGGER.error( "ZuyuanyzServiceImpl.addYz异常" + e.getMessage() );
            return false;
        }
    }

    //根据医嘱id查找医嘱
    @Override
    public Zuyuanyz qryYZById(int zId) {
        Zuyuanyz zuyuanyz = null;
        try {
            zuyuanyz = zyyzMapper.qryYZById( zId );
        } catch (Exception e) {
            LOGGER.error( "ZuyuanyzServiceImpl.qryYZById异常" + e.getMessage() );
        }
        return zuyuanyz;
    }

    //执行医嘱
    @Override
    public boolean updateYZ(Zuyuanyz zuyuanyz) {
        int row = 0;
        try {
            row = zyyzMapper.updateYZ( zuyuanyz );
            if (row == 1) {
                return true;
            } else {
                return false;
            }
        } catch (Exception e) {
            LOGGER.error( "ZuyuanyzServiceImpl.updateYZ异常" + e.getMessage() );
            return false;
        }
    }


}
